/** 修改公告 */
const blogNews = document.querySelector('#blog-news')
const sidebarNews = document.querySelector('#sidebar_news')
const gongGao = document.createElement('div')
gongGao.classList.add('img')
gongGao.innerHTML = `<img src="https://api.ixiaowai.cn/api/api.php" alt="">`
sidebarNews.insertBefore(gongGao, blogNews)
document.querySelector('#profile_block').childNodes[0].remove()
document.querySelector('#profile_block').childNodes[2].remove()
document.querySelector('#profile_block').childNodes[5].remove()
document.querySelector('#profile_block').childNodes[8].remove()
document.querySelector('#profile_block').childNodes[2].remove()
document.querySelector('#profile_block').childNodes[4].remove()
document.querySelector('#profile_block').childNodes[6].remove()
const yuanling = document.querySelector('#profile_block').childNodes[2].innerText
document.querySelector('#profile_block').childNodes[2].innerHTML = `${yuanling}<br>园龄`

const fensi = document.querySelector('#profile_block').childNodes[4].innerText
document.querySelector('#profile_block').childNodes[4].innerHTML = `${fensi}<br>粉丝`

const guanzhu = document.querySelector('#profile_block').childNodes[6].innerText
document.querySelector('#profile_block').childNodes[6].innerHTML = `${guanzhu}<br>关注`

// 文章日期
const dateArr = document.querySelectorAll('.day .postDesc')
dateArr.forEach(item => {
  const dataNew = item.innerHTML.replace(/^posted @/, '').replace(/rain_sparse/, '')
  item.innerHTML = dataNew
})

//今日诗词
const mainFooter = document.createElement('div')
mainFooter.classList.add('mainFooter')
mainFooter.innerHTML = `
  <div id="poem_sentence"></div>
  <div id="poem_info"></div>
`
const main = document.querySelector('#main')
const sideBar = document.querySelector('#sideBar')
main.insertBefore(mainFooter, sideBar)

jinrishici.load(function (result) {
  var sentence = document.querySelector('#poem_sentence')
  var info = document.querySelector('#poem_info')
  sentence.innerHTML = result.data.content
  info.innerHTML =
    '【' + result.data.origin.dynasty + '】' + result.data.origin.author + '《' + result.data.origin.title + '》'
})

// 返回顶部
const home = document.querySelector('#home')
const div = document.createElement('div')
div.classList.add('toTop')
home.append(div)
const forFlow = document.querySelector('#mainContent')
forFlow.onscroll = function () {
  if (forFlow.scrollTop > 100) {
    $('.toTop').fadeIn(300)
  } else {
    $('.toTop').fadeOut(300)
  }
}
document.querySelector('.toTop').addEventListener('click', function () {
  $('#mainContent').animate({ scrollTop: '0px' }, 'slow')
})
